home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / PickOne / sources / PickOne_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.6 KB  |  250 lines  |  [TEXT/CWIE]

  1. /*  main.c                                                                            
  2.                                                                                     
  3.   This is PickOne, a sample app designed to show how getting UV data from
  4.   a pick object can be used to draw on a texture. This app does not have        
  5.   graceful error handling - it's purpose is to demonstrate UV picking.                                                                        
  6.                                                                                     
  7.   Michael Bishop - August 21 1996                                                    
  8.   Nick Thompson
  9.   Robert Dierkes                                                                                
  10.   (c)1994-96 Apple Computer Inc., All Rights Reserved                                
  11.  
  12. */
  13.  
  14. /*  system headers */
  15. #include    <Devices.h>
  16. #include    <Dialogs.h>
  17. #include    <DiskInit.h>
  18. #include    <Events.h>
  19. #include    <Fonts.h>
  20. #include    <Menus.h>
  21. #include    <PictUtils.h>
  22. #include    <QDOffScreen.h>
  23. #include    <QuickDraw.h>
  24. #include    <SegLoad.h>
  25. #include    <StandardFile.h>
  26. #include    <TextEdit.h>
  27.  
  28. #include    "PickOne_main.h"
  29. #include    "PickOne_utility.h"
  30. #include    "PickOne_document.h"
  31. #include    "PickOne_window.h"
  32. #include    "PickOne_menu.h"
  33. #include    "PickOne_event.h"
  34.  
  35. #include    "QD3D.h"
  36.  
  37.  
  38. /* -------------------------------------------------------------------------------------------
  39. ** function prototypes
  40. */
  41.  
  42. static void InitToolbox( void ) ;
  43. static void Main_EventLoop( void ) ;
  44. static void    Main_Init( short mBarResourceID, short numMoremasters);
  45. static void    Main_Destroy( void );
  46.  
  47.  
  48. /* -------------------------------------------------------------------------------------------
  49. ** Global Variables
  50. */
  51.  
  52. Boolean         gQuitFlag         = false ;
  53. Boolean            gForeground        = true ;
  54. short            gTicks            = 1 ;
  55.  
  56. /* -------------------------------------------------------------------------------------------
  57. **  main() 
  58. **  entry point for the application, initialize the toolbox, initialize QuickDraw 3D 
  59. **  and enter the main event loop.  On exit from the main event loop, we want to call 
  60. **  the QuickDraw 3D exit function to clean up QuickDraw 3d. 
  61. */
  62.  
  63. void main( void ) 
  64. {
  65.     Main_Init( kMBARResID, 5 ) ;            /* initialise the toolbox, load our menubar */
  66.  
  67.     Document_New();
  68.     
  69.     Main_EventLoop() ;
  70.     
  71.     /* tear down any we allocated */
  72.     Main_Destroy() ;    
  73.     
  74.     /* and bail */
  75.     ExitToShell() ;
  76. }
  77.  
  78. /*    -------------------------------------------------------------------------------------------
  79. **    Main_Init
  80. **    Initialize our environment, pass in the mbar resource ID, and also the number of calls 
  81. **    to make to moremasters
  82. */
  83.  
  84. void Main_Init( short mBarResourceID, short numMoremasters)
  85. {
  86.     Handle        menuBar = nil;
  87.     short        loopCounter ;
  88.     TQ3Status    myStatus ;
  89.  
  90.     MaxApplZone() ;        /* max out the apps heap */
  91.     
  92.     for( loopCounter = 0; loopCounter < numMoremasters ; loopCounter++ )
  93.         MoreMasters() ;
  94.         
  95.     InitToolbox() ;
  96.  
  97.     
  98.     /* initialize anything else we need to */
  99.     
  100.     /* init QuickDraw 3D, open a connection to the QuickDraw 3D library */
  101.     myStatus = Q3Initialize();
  102.  
  103.     if ( myStatus == kQ3Failure )
  104.         DebugStr("\pQ3Initialize returned failure.");            
  105.     
  106.     
  107.     /*  initialize application globals */
  108.     
  109.     gQuitFlag = false;
  110.     gForeground = true;
  111.     gTicks        = 1;
  112.     /* load the application menu bar */
  113.     
  114.     menuBar = GetNewMBar( mBarResourceID );    /* Read menus into menu bar, MBAR res id is 128 */
  115.     
  116.     if ( menuBar == nil )
  117.          ExitToShell();                        /* if we dont have it then quit - your app */
  118.                                              /* needs a dialog here */
  119.  
  120.     SetMenuBar(menuBar);                    /* Install menus */
  121.     DisposHandle(menuBar);
  122.     
  123.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* Add DA names to Apple menu, ID 128 */
  124.  
  125.     Menu_Adjust() ;
  126.     DrawMenuBar();
  127. }
  128.  
  129.  
  130.  
  131. void Main_Destroy( void )
  132. {
  133.     Window_DestroyAll();
  134.     
  135.     Q3Exit() ;
  136.  
  137. }
  138.  
  139. /*    --------------------------------------------------------------------
  140. **    InitToolbox
  141. **    Initialize the toolbox managers
  142. */
  143. void InitToolbox( void )
  144. {
  145.     
  146.     InitGraf( &qd.thePort );
  147.     InitFonts();
  148.     InitWindows();
  149.     InitCursor();
  150.     InitDialogs( nil ) ;
  151.  
  152.     FlushEvents( everyEvent, 0 ) ;
  153. }
  154.  
  155.  
  156.  
  157. /*    --------------------------------------------------------------------
  158. **    Main_EventLoop
  159. **    The heart of the app. Handles all interaction
  160. */
  161. void Main_EventLoop()
  162. {
  163.     EventRecord     theEvent;
  164.     WindowPtr       theWindow;
  165.     short           thePart;
  166.     Rect            screenRect;
  167.     Point            aPoint = {100, 100};
  168.     Boolean            eventPresent = false;
  169.  
  170.     while( !gQuitFlag )
  171.     {
  172.         eventPresent = WaitNextEvent( everyEvent, &theEvent, gTicks, nil );
  173.         
  174.         if (eventPresent == true)
  175.         {
  176.             switch (theEvent.what) {
  177.                 case mouseDown:
  178.                 
  179.                     thePart = FindWindow( theEvent.where, &theWindow ) ;
  180.                     
  181.                     switch( thePart ) {
  182.                         case inMenuBar: 
  183.                             Menu_Adjust() ;
  184.                             Menu_HandleCommand(MenuSelect(theEvent.where));
  185.                             break;
  186.                         
  187.                         case inDrag:
  188.                             screenRect = (**GetGrayRgn()).rgnBBox;
  189.                             DragWindow( theWindow, theEvent.where, &screenRect );
  190.                             break ;
  191.                     
  192.                         case inContent:
  193.                             if (theWindow != FrontWindow())
  194.                                 SelectWindow( theWindow );
  195.                             Window_DoContent(theWindow, &theEvent);
  196.                             break ;
  197.                     
  198.                         case inGoAway:
  199.                             if (TrackGoAway( theWindow, theEvent.where )) {
  200.                                 Document_Dispose( Window_GetDocument(theWindow) ) ;
  201.                             }
  202.                             break ;
  203.                             
  204.                         default:
  205.                             break ;
  206.                     }
  207.                     break ;
  208.                             
  209.                         
  210.                 case updateEvt:
  211.                 
  212.                     theWindow = (WindowPtr)theEvent.message;
  213.                     Window_Update( theWindow ) ;
  214.                     break ;
  215.                     
  216.                 case keyDown:
  217.                 case autoKey:
  218.                     Event_HandleKeyPress(&theEvent);
  219.                     break;
  220.                     
  221.                 case diskEvt:
  222.                     if ( Utility_HiWrd(theEvent.message) != noErr ) 
  223.                         (void) DIBadMount(aPoint, theEvent.message);
  224.                     break;
  225.                     
  226.                 case osEvt:
  227.                     Event_DoOSEvent(theEvent);
  228.                     break;
  229.  
  230.                 case activateEvt:
  231.                     break;
  232.             }
  233.         }
  234.         else {
  235. /*                Event_DoNull();    */    /* Handle the Null Event */
  236.  
  237.         }
  238.     }
  239. }
  240.  
  241. /*    --------------------------------------------------------------------
  242. **    Main_DoAbout
  243. **    Display the About Box
  244. */
  245. void Main_DoAbout( void )
  246. {
  247.     short                itemHit ;
  248.     
  249.     itemHit = Alert ( 128, nil ) ;
  250. }